package com.bytedance.frameworks.base.mvp;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class Presenter<V extends View> {
    public V mView;
    public Context mContext;
    private List <Interactor> interactorList;

    public Presenter(Context context) {
        this.interactorList = new ArrayList();
        this.mContext = context;
    }

    public final void setView(V view) {
        this.mView = view;
        Iterator<Interactor> iterator = this.interactorList.iterator();
        while(iterator.hasNext()) {
            iterator.next().setView(view);
        }
    }

    public void onCreate(Bundle extraBundle, Bundle savedBundle) {
        Iterator<Interactor> iterator = this.interactorList.iterator();
        while(iterator.hasNext()) {
            iterator.next().onCreate(extraBundle, savedBundle);
        }
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    }

    public final void releaseView() {
        this.mView = null;
        Iterator<Interactor> iterator = this.interactorList.iterator();
        while(iterator.hasNext()) {
            iterator.next().releaseView();
        }
    }

    public final void addInteractor(Interactor interactor) {
        this.interactorList.add(interactor);
        if(this.hasView()) {
            interactor.setView(this.mView);
        }
    }

    public void onResume() {
    }

    public void onPause() {
    }

    public void onDestroy() {
    }

    public final boolean hasView() {
        return this.mView != null;
    }
}

